package com.woniu.springbootrbac.controller;


import com.woniu.springbootrbac.dto.RoleDto;
import com.woniu.springbootrbac.entity.SysRole;
import com.woniu.springbootrbac.service.RoleService;
import com.woniu.springbootrbac.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/roles")
public class RoleController {

    @Autowired
    private RoleService service;

    @GetMapping("{uid}")
    public Result selAll(@PathVariable Long uid){
        List<SysRole> sysRoles = service.selAll();
        List<Integer> integers = service.selectRolesIdByUid(uid);
        return Result.ok().data("roleList",sysRoles).data("checkList",integers);
    }

    @PostMapping("")
    public Result update(@RequestBody RoleDto roleDto){
        int i = service.insertRole(roleDto);
        return Result.ok();
    }

    @GetMapping("")
    public Result sel(){
        List<SysRole> sysRoles = service.selAll();
        return Result.ok().data("roleList",sysRoles);
    }
}
